//
//  YZManagerViewController.m
//  kuaiyi
//
//  Created by wyman on 16/5/4.
//
//

#import "YZManagerViewController.h"
#import "YZShowCase.h"
#import <Masonry.h>
#import "YZNetWorkTool.h"
#import "YZdetailTableView.h"
#import <SVProgressHUD.h>
@interface YZManagerViewController ()


/**
 *  基本信息的属性设置
 */
@property (weak, nonatomic) IBOutlet UILabel *nameLable;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumber;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;

//显示个人资料
@property (weak, nonatomic) IBOutlet UIView *infoView;

//显示病历信息
@property (nonatomic, strong) YZdetailTableView *showCaseView;
@end

@implementation YZManagerViewController

//static YZManagerViewController *_instance;

-(instancetype)init{


            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"YZManager" bundle:nil];
            return [sb instantiateInitialViewController];


}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = YZGreenColor;
    //设置标题
    //self.title = @"\病历管理";
    self.iconView.image=[UIImage imageNamed:@"u=564080184,3790533830&fm=21&gp=0"];
    self.iconView.layer.cornerRadius = _iconView.bounds.size.width/2;

    //设置标题颜色
    self.navigationController.navigationBar.titleTextAttributes = @{
                                    NSForegroundColorAttributeName:[UIColor whiteColor]
                                                                   };
    //TODO:测试
    //设置属性信息
    self.nameLable.text = @"王云财";
    self.numberLabel.text = @"11221991144933";
    self.phoneNumber.text = @"18216101102";
    [self setupUI];
    
}
-(void)setupUI{
   
    //添加控件,设置frame
    [self.view addSubview:self.showCaseView];
    

    [self.showCaseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.infoView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.bottomView.mas_top);
        
    }];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didClicked:) name:@"delete" object:nil];

}
//懒加载控件
-(YZdetailTableView *)showCaseView
{
    if (_showCaseView == nil) {
        _showCaseView = [[YZdetailTableView alloc]init];
        

    }
       return _showCaseView;
}




-(void)didClicked:(NSNotification *)notification{
    
    NSDictionary *weatherInfo = notification.userInfo;
    
    NSIndexPath *indexPath = weatherInfo[@"ills"];
    
    NSString *title = @"是否删除";
    NSString *message = NSLocalizedString(@"A message should be a short, complete sentence.", nil);
    NSString *cancelButtonTitle =@"取消";
    NSString *otherButtonTitle = @"删除";
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    __weak typeof(self) selfVc = self;

    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
       
        [selfVc.showCaseView.detailArray removeObjectAtIndex:indexPath.row];
        
        [selfVc.showCaseView reloadData];
        
        
        [SVProgressHUD showWithStatus:@"删除成功"];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];

        });
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [self presentViewController:alertController animated:YES completion:nil];

}

@end
